import java.util.Set;
import java.util.TreeSet;

/**
 * TreeSet其实就是堆排(小堆顶),基本数据类型和String可以直接排序,引用类要自定义比较器
 */
public class TreeSetDemo {
    public static void main(String[] args) {
        Set<Student> sets = new TreeSet<>();
        Student s1 = new Student(18,"小刘",1.76,56.3);
        Student s2 = new Student(18,"小刘",1.76,56.3);
        Student s3 = new Student(20,"小陈",1.74,53.4);
        Student s4 = new Student(19,"小赵",1.77,57.3);
        Student s5 = new Student(21,"小吴",1.79,60.2);

        sets.add(s1);
        sets.add(s2);
        sets.add(s3);
        sets.add(s4);
        sets.add(s5);
        System.out.println(sets);

        System.out.println("----------------------------------------" +
                "---------------------------------------------------" +
                "---------------------------------------------------" +
                "---------------------------------------------------");
        //可以在treeset中定义比较器,已用lambda简化
        Set<Student> set2 = new TreeSet<>(( o1,  o2) -> o1.getAge()-o2.getAge());
        set2.add(s1);
        set2.add(s2);
        set2.add(s3);
        set2.add(s4);
        set2.add(s5);
        System.out.println(set2);
    }
}
